
Density function, cumulative distribution function, quantile function
and random number generation for the generalized inverse Gaussian
distribution with parameter vector param
. Utility routines are
included for the derivative of the density function and to find
suitable break points for use in determining the distribution function.
dgig(x, chi = 1, psi = 1, lambda = 1,
param = c(chi, psi, lambda), KOmega = NULL)
pgig(q, chi = 1, psi = 1, lambda = 1,
param = c(chi,psi,lambda), lower.tail = TRUE,
ibfTol = .Machine$double.eps^(0.85), nmax = 200)
qgig(p, chi = 1, psi = 1, lambda = 1,
param = c(chi, psi, lambda), lower.tail = TRUE,
method = c("spline", "integrate"),
nInterpol = 501, uniTol = 10^(-7),
ibfTol = .Machine$double.eps^(0.85), nmax =200, ...)
rgig(n, chi = 1, psi = 1, lambda = 1,
param = c(chi, psi, lambda))
rgig1(n, chi = 1, psi = 1, param = c(chi, psi))
ddgig(x, chi = 1, psi = 1, lambda = 1,
param = c(chi, psi, lambda), KOmega = NULL)
dgig
gives the density, pgig
gives the distribution
function, qgig
gives the quantile function, and rgig
generates random variates. rgig1
generates random variates in
the special case where
ddgig
gives the derivative of dgig
.
Vector of quantiles.
Vector of probabilities.
Number of observations to be generated.
A shape parameter that by default holds a value of 1.
Another shape parameter that is set to 1 by default.
Shape parameter of the GIG distribution. Common to all forms of parameterization. By default this is set to 1.
Parameter vector taking the form c(chi, psi, lambda)
for rgig
, or c(chi, psi)
for rgig1
.
Character. If "spline"
quantiles are found from a
spline approximation to the distribution function. If
"integrate"
, the distribution function used is always obtained
by integration.
Logical. If TRUE
, probabilities are
Sets the value of the Bessel function in the density or derivative of the density. See Details.
Value of tolerance to be passed to
incompleteBesselK
by pgig
.
Value of maximum order of the approximating series to be
passed to incompleteBesselK
by pgig
.
The number of points used in qgig for cubic spline
interpolation (see splinefun
) of the distribution function.
Value of tol
in
calls to uniroot
. See uniroot
.
Passes arguments to uniroot
. See Details.
David Scott d.scott@auckland.ac.nz, Richard Trendall, and Melanie Luen.
The generalized inverse Gaussian distribution has density
for
The generalized inverse Gaussian distribution is investigated in detail in Jörgensen (1982).
Use gigChangePars
to convert from the
pgig
calls the function
incompleteBesselK
from the package
DistributionUtils to integrate the density function
dgig
. This can be expected to be accurate to about 13 decimal
places on a 32-bit computer, often more accurate. The algorithm used
is due to Slavinsky and Safouhi (2010).
Calculation of quantiles using qgig
permits the use of two
different methods. Both methods use uniroot
to find the value
of pghyp
. This is what
is done if the method is specified as "integrate"
. It is clear
that the time required for this approach is roughly linear in the
number of quantiles being calculated. A Q-Q plot of a large data set
will clearly take some time. The alternative (and default) method is
that for the major part of the distribution a spline approximation to
uniroot
with
this approximation. For extreme values (for which the tail probability
is less than "spline"
.
If accurate probabilities or quantiles are required, tolerances
(intTol
and uniTol
) should be set to small values, say
method
= "integrate"
. Generally then accuracy might be expected to be at
least .Machine$double.eps^0.25 = 0.0001220703
is a typical value.
Generalized inverse Gaussian observations are obtained via the algorithm of Dagpunar (1989).
Dagpunar, J.S. (1989). An easily implemented generalised inverse Gaussian generator. Commun. Statist. -Simula., 18, 703--710.
Jörgensen, B. (1982). Statistical Properties of the Generalized Inverse Gaussian Distribution. Lecture Notes in Statistics, Vol. 9, Springer-Verlag, New York.
Slevinsky, Richard M., and Safouhi, Hassan (2010) A recursive algorithm for the G transformation and accurate computation of incomplete Bessel functions. Appl. Numer. Math., In press.
param <- c(2, 3, 1)
gigRange <- gigCalcRange(param = param, tol = 10^(-3))
par(mfrow = c(1, 2))
curve(dgig(x, param = param), from = gigRange[1], to = gigRange[2],
n = 1000)
title("Density of the\n Generalized Inverse Gaussian")
curve(pgig(x, param = param), from = gigRange[1], to = gigRange[2],
n = 1000)
title("Distribution Function of the\n Generalized Inverse Gaussian")
dataVector <- rgig(500, param = param)
curve(dgig(x, param = param), range(dataVector)[1], range(dataVector)[2],
n = 500)
hist(dataVector, freq = FALSE, add = TRUE)
title("Density and Histogram\n of the Generalized Inverse Gaussian")
DistributionUtils::logHist(dataVector, main =
"Log-Density and Log-Histogram\n of the Generalized Inverse Gaussian")
curve(log(dgig(x, param = param)), add = TRUE,
range(dataVector)[1], range(dataVector)[2], n = 500)
par(mfrow = c(2, 1))
curve(dgig(x, param = param), from = gigRange[1], to = gigRange[2],
n = 1000)
title("Density of the\n Generalized Inverse Gaussian")
curve(ddgig(x, param = param), from = gigRange[1], to = gigRange[2],
n = 1000)
title("Derivative of the Density\n of the Generalized Inverse Gaussian")
Run the code above in your browser using DataLab